﻿/* jsonWeather*/
function channelvnWather(instanceName) {
    this.host = 'http://weather.channelvn.net';
    //http://weather.channelvn.net/ProxyHandler.ashx?MethodName=ChannelvnWeather&CallBack=channelvn.OnLoaded&RequestType=json

    this.script_folder = this.host + '/www/dantri';

    this.script_object = null;

    this.instance_name = instanceName;

    this.LoadDataWeather = function () {
        this.CreateScriptObject(this.host + '/ProxyHandler.ashx?MethodName=ChannelvnWeather&CallBack=' + this.instance_name + '.OnLoadedWeather&RequestType=json');

    };
    this.OnLoadedWeather = function (data, methodName) {

        var newsData = eval(data);
        var outputWeatherImage = '';
        var outputWeather = '';
        var image = '';

        var city = "T.P Hà Nội";

        try {

            if (document.getElementById("cbSelect").value != null || document.getElementById("cbSelect").value != '') {
                city = document.getElementById("cbSelect").value;

            } else {
                city = "T.P Hà Nội";
            }

        }

        catch (err) {
            //TODO:
        }


        for (var j = 0; j < 8; j++) {
            if (city == newsData.ChannevnJSon.Weather[j].City_Name) {
                image = newsData.ChannevnJSon.Weather[j].City_Weather;
                outputWeather += '<div>';
                outputWeather += '<span class="temparete">' + newsData.ChannevnJSon.Weather[j].City_Temp + '</span></div>';
            }
        }

        if (image == 'Không mưa') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_026.png" alt="" />';
        } else if (image == 'Có mưa') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_017.png" alt="" />';
        } else if (image == 'Lặng gió') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_010.png" alt="" />';
        } else if (image == 'Nhiều mây') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_026.png" alt="" />';
        } else if (image == 'Ít mây') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_026.png" alt="" />';
        } else if (image == 'Mây thay đổi') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_002.png" alt="" />';
        } else if (image == 'Có mưa phùn') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_017.png" alt="" />';
        }
        else if (image == 'Nhiều mây, không mưa') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_026.png" alt="" />';
        }
        else if (image == 'Mây thay đổi, trời nắng') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_010.png" alt="" />';
        }
        else if (image == 'Có mưa rào') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_014.png" alt="" />';
        }
        else if (image == 'Đêm nhiều mây') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_003.png" alt="" />';
        }
        else if (image == 'Đêm có mây') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_009.png" alt="" />';
        }
        else if (image == 'Ít mây, trời nắng') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_010.png" alt="" />';
        }
        else if (image == 'Có mưa rào và dông') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_024.png" alt="" />';
        }
        else if (image == 'Trời trở gió') {
            outputWeatherImage += '<div class="img">';
            outputWeatherImage += '<img src="http://soha4.vcmedia.vn/Images/Icon140/Yahoo_Weather_025.png" alt="" />';
        }
        try {
            document.getElementById('divWeatherImage').innerHTML = outputWeatherImage;
            document.getElementById('divWeather').innerHTML = outputWeather;
        }

        catch (err) {
            //TODO:
        }

    };

    this.CreateScriptObject = function (src) {

        if (this.script_object != null) {
            this.RemoveScriptObject();

        }

        this.script_object = document.createElement('script');

        this.script_object.setAttribute('type', 'text/javascript');

        this.script_object.setAttribute('src', src);

        var head = document.getElementsByTagName('head')[0];

        head.appendChild(this.script_object);

    };
    this.RemoveScriptObject = function () {
        this.script_object.parentNode.removeChild(this.script_object);

        this.script_object = null;
    };
}

function put() {
    var channelweather1 = new channelvnWather('channelweather');
    channelweather1.LoadDataWeather();
}

/*eof jsonWeather*/